﻿using Validity.Contexts;
using Validity.Localization;
using Validity.Rules;

namespace Validity
{
  public static class IsNotNullConstraint
  {
    public static IConditionalValidationContext<TObject, TValue> IsNotNull<TObject, TValue>(this IValidationContext<TObject, TValue> context)
      where TValue : class
    {
      context.AddRule(new Rule<TObject, TValue>(
        (obj, val) => val != null,
        (obj, val) => RuleViolations.NotNull
      ));

      return new ConditionalValidationContext<TObject, TValue>(context);
    }
  }
}
